home *** CD-ROM | disk | FTP | other *** search
- #include "frame.h"
- #include "dkbproto.h"
-
- #include <stdlib.h>
- #include <setjmp.h>
- #include <Controls.h>
- #include <Desk.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Files.h>
- #include <Fonts.h>
- #include <Memory.h>
- #include <Menus.h>
- #include <Notification.h>
- #include <OSEvents.h>
- #include <OSUtils.h>
- #include <Packages.h>
- #include <QuickDraw.h>
- #include <QuickDraw32Bit.h>
- #include <Resources.h>
- #include <SegLoad.h>
- #include <TextEdit.h>
- #include <Types.h>
- #include <Windows.h>
- #include <CursorCtl.h>
-
- #define maxlines 300
- #define wheight 25
- #define wwidth 80
- #define margin 3
-
- #define MYBUFSIZE 256
- #define N_ARGS 32
-
- void MacDawdle(void);
-
- typedef struct
- {
- char paths[256];
- char filename[32];
- short vRefNum;
- short width, height, from, to;
- float threshold;
- short bufsize, quality;
- char cr_file, dump, raw, targa;
- char antialias, use_buf, resume, pause;
- char verbose, debug;
- /* Options Menu states */
- char dither;
- } set_rec;
-
- typedef unsigned char TEXTBUF[maxlines][wwidth + 1];
- typedef TEXTBUF *TEXTPTR;
-
- volatile extern int Stop_Flag;
- extern unsigned int Options;
- jmp_buf env;
- int dkb_runs = 0; /* Used to determine the menu states. */
-
- PixMapHandle pm;
- WindowPtr plot_window = NULL;
- Ptr plot_pixmap = NULL;
- Rect plot_bounds;
-
- FILE *my_out, *my_err;
- WindowPtr myWindow[2];
- MenuHandle myMenus[5];
- RgnHandle theUpdateRgn;
- ControlHandle myScroll[2];
- char run_flag = 0, quit_flag = 0, waiting_for_esc = 0;
- EventRecord myEvent;
- int nlines[2] = {0, 0}, topline[2] = {0, 0}, active[2] = {0, 0};
- int cur_wnd, ARGC;
- TEXTPTR myText;
- Rect tRect = {0, 0, 11 * wheight + 2 * margin - 1, 6 * wwidth + 2 * margin - 1};
- long prev_upd_cons, prev_upd_plot;
- char buf0[MYBUFSIZE], buf1[MYBUFSIZE], *ARGV[32], argstr[1024], *argptr;
- set_rec *settings, **settings_h;
-
- /* --- These are the required routines for machine.h --- */
-
- void display_init(int width, int height)
- {
- long *p, *q, pmsize;
- Handle h;
- Rect brect;
-
- SetRect(&plot_bounds, 0, 0, width, height);
- pmsize = 4 * width * height;
- h = NewHandle(pmsize);
- if (h)
- {
- MoveHHi(h);
- HLock(h);
- plot_pixmap = *h;
- q = (long *) ((long) plot_pixmap + pmsize);
- for (p = (long *) plot_pixmap; p < q; *p++ = -1);
- (*pm)->bounds = plot_bounds;
- (*pm)->rowBytes = width * 4 | 0x8000;
- (*pm)->baseAddr = plot_pixmap;
- }
- else
- plot_pixmap = NULL;
-
- brect = plot_bounds;
- OffsetRect(&brect, 8, 45);
- plot_window = NewCWindow(NULL, &brect, "\pPlot", true, noGrowDocProc,
- (WindowPtr) -1L, false, 0);
- }
-
- void display_plot(int x, int y, char Red, char Green, char Blue)
- {
- RGBColor c;
- char *pptr;
-
- SetPort(plot_window);
- c.red = ((short) Red) << 8;
- c.green = ((short) Green) << 8;
- c.blue = ((short) Blue) << 8;
- SetCPixel(x, y, &c);
-
- if (plot_pixmap)
- {
- pptr = (char *) ((long) plot_pixmap + 4 * (plot_bounds.right * y + x));
- *pptr++ = 0;
- *pptr++ = Red;
- *pptr++ = Green;
- *pptr = Blue;
- }
- }
-
- void display_close(void)
- {
- Handle h;
- NMRec myNote;
-
- if ((Options & PROMPTEXIT) && !quit_flag)
- {
- fprintf(stderr, "### Press [Esc] to continue...\n");
- SetWTitle(plot_window, "\pPress [Esc]");
- SelectWindow(plot_window);
- myNote.qType = nmType;
- myNote.nmFlags = 0;
- myNote.nmPrivate = 0;
- myNote.nmReserved = 0;
- myNote.nmMark = 0;
- myNote.nmSIcon = GetResource('SICN', 128);
- myNote.nmSound = (Handle) -1;
- myNote.nmStr = NULL;
- myNote.nmResp = NULL;
- NMInstall((QElemPtr) &myNote);
- DisableItem(myMenus[2], 0);
- DrawMenuBar();
-
- waiting_for_esc = 1;
- while (waiting_for_esc)
- MacDawdle();
-
- NMRemove((QElemPtr) &myNote);
- EnableItem(myMenus[2], 0);
- DrawMenuBar();
- }
- DisposeWindow(plot_window);
- plot_window = NULL;
- if (plot_pixmap)
- {
- h = RecoverHandle(plot_pixmap);
- HUnlock(h);
- DisposHandle(h);
- plot_pixmap = NULL;
- }
- }
-
- void display_finished(void)
- {
- }
-
- /* --- And now for the real Mac stuff --- */
-
- char *PrintTime()
- {
- static char t[10];
- unsigned long secs;
-
- GetDateTime(&secs);
- iutimestring(secs, true, t);
- return t;
- }
-
- void call_main(int argc, char *argv[])
- {
- if (!setjmp(env))
- {
- fprintf(stderr, "### %s Starting...\n\n", PrintTime());
- dkb_runs = 1;
- Main(argc, argv);
- dkb_runs = 0;
- fprintf(stderr, "### %s Normal termination.\n\n", PrintTime());
- }
- run_flag = 0;
- }
-
- void exit(int status)
- {
- dkb_runs = 0;
- fprintf(stderr, "### %s Terminated by exit(%d).\n\n", PrintTime(), status);
- longjmp(env, 1);
- }
-
- char *getenv(const char *name)
- {
- if (!strcmp(name, "DKBOPT"))
- return "";
- else
- return NULL;
- }
-
- void SetTypeAndCreator(char *name, long type, long creator)
- {
- FInfo finf;
-
- getfinfo(name, 0, &finf);
- finf.fdType = (OSType) type;
- finf.fdCreator = (OSType) creator;
- setfinfo(name, 0, &finf);
- }
-
- void UpdateLine(int n)
- {
- int L;
-
- if ((L = n + topline[cur_wnd]) < nlines[cur_wnd])
- {
- SetPort(myWindow[cur_wnd]);
- MoveTo(margin, 11 * n + 8 + margin);
- drawstring(myText[cur_wnd][L]);
- }
- }
-
- void UpdateText(void)
- {
- int i;
-
- for (i = 0; i < wheight; i++)
- UpdateLine(i);
- }
-
- void ScrollBits(void)
- {
- int prevTopLine, offset;
-
- prevTopLine = topline[cur_wnd];
- topline[cur_wnd] = GetCtlValue(myScroll[cur_wnd]);
- offset = prevTopLine - topline[cur_wnd];
- ScrollRect(&tRect, 0, offset * 11, theUpdateRgn);
- ClipRect(&(*theUpdateRgn)->rgnBBox);
- UpdateText();
- ClipRect(&myWindow[cur_wnd]->portRect);
- }
-
- pascal void ScrollUp(ControlHandle whichControl, short part)
- {
- if (part == inUpButton)
- {
- SetCtlValue(whichControl, GetCtlValue(whichControl) - 1);
- ScrollBits();
- }
- }
-
- pascal void ScrollDown(ControlHandle whichControl, short part)
- {
- if (part == inDownButton)
- {
- SetCtlValue(whichControl, GetCtlValue(whichControl) + 1);
- ScrollBits();
- }
- }
-
- void PageScroll(short code, short amount)
- {
- Point pt;
-
- do
- {
- GetMouse(&pt);
- if (TestControl(myScroll[cur_wnd], pt) == code)
- {
- SetCtlValue(myScroll[cur_wnd], GetCtlValue(myScroll[cur_wnd]) + amount);
- ScrollBits();
- }
- }
- while (StillDown());
- }
-
- void PrintLine(char s[])
- {
- short max;
-
- SetPort(myWindow[cur_wnd]);
- if (nlines[cur_wnd] == maxlines)
- {
- BlockMove(&myText[cur_wnd][1], &myText[cur_wnd][0], ((long) wwidth + 1) * (maxlines - 1));
- strncpy(myText[cur_wnd][nlines[cur_wnd] - 1], s, wwidth);
- SetCtlValue(myScroll[cur_wnd], nlines[cur_wnd] - wheight);
- topline[cur_wnd]--;
- ScrollBits();
- UpdateLine(wheight - 1);
- }
- else
- {
- strncpy(myText[cur_wnd][nlines[cur_wnd]], s, wwidth);
- myText[cur_wnd][nlines[cur_wnd]][wwidth] = 0;
- if (nlines[cur_wnd] < wheight)
- UpdateLine(nlines[cur_wnd]++);
- else
- {
- SetCtlMax(myScroll[cur_wnd], max = ++nlines[cur_wnd] - wheight);
- SetCtlValue(myScroll[cur_wnd], max);
- ScrollBits();
- UpdateLine(wheight - 1);
- }
- }
- }
-
- void AboutDKB(void)
- {
- char *s = "DKBTrace";
-
- Stop_Flag = 0;
- call_main(1, &s);
- }
-
- void AddArg(const char *s)
- {
- ARGV[ARGC++] = argptr;
- while (*argptr++ = *s++);
- }
-
- pascal Boolean MyFilter(DialogPtr theDialog, EventRecord *theEvent, short *itemHit)
- {
- return false;
- }
-
- short PinValue(short *x, short a, short b)
- {
- if (*x < a)
- *x = a;
- else
- if (*x > b)
- *x = b;
- }
-
- void StartDKB(void)
- {
- DialogPtr myDialog;
- short i, itemHit, dummyInt, temp_vRefNum;
- Handle dummyHand;
- Rect displayRect;
- ControlHandle cntl[23];
- char s1[256], s2[256], *s2_p, *s3_p, c;
- SFReply reply;
- SFTypeList typelist;
- Point where;
-
- myDialog = GetNewDialog(128, NULL, (WindowPtr) -1);
- for (i = 1; i < 23; i++)
- GetDItem(myDialog, i, &dummyInt, (Handle *) &cntl[i], &displayRect);
- setitext((Handle) cntl[4], settings->filename);
- sprintf(s1, "%d", settings->width); setitext((Handle) cntl[5], s1);
- sprintf(s1, "%d", settings->height); setitext((Handle) cntl[6], s1);
- sprintf(s1, "%d", settings->quality); setitext((Handle) cntl[7], s1);
- sprintf(s1, "%d", settings->from); setitext((Handle) cntl[8], s1);
- sprintf(s1, "%d", settings->to); setitext((Handle) cntl[9], s1);
- SetCtlValue(cntl[10], settings->antialias);
- sprintf(s1, "%.2f", settings->threshold); setitext((Handle) cntl[11], s1);
- SetCtlValue(cntl[12], settings->use_buf);
- sprintf(s1, "%d", settings->bufsize); setitext((Handle) cntl[13], s1);
- SetCtlValue(cntl[14], settings->cr_file);
- SetCtlValue(cntl[15], settings->dump);
- SetCtlValue(cntl[16], settings->raw);
- SetCtlValue(cntl[17], settings->targa);
- SetCtlValue(cntl[18], settings->resume = 0);
- SetCtlValue(cntl[19], settings->pause);
- SetCtlValue(cntl[20], settings->verbose);
- SetCtlValue(cntl[21], settings->debug);
- setitext((Handle) cntl[22], settings->paths);
- SelIText(myDialog, 5, 0, 32767);
- if (!(*settings->filename))
- HiliteControl(cntl[1], 255);
-
- do
- {
- ModalDialog(MyFilter, &itemHit);
- switch (itemHit)
- {
- case 3:
- where.h = where.v = 82;
- typelist[0] = 'TEXT';
- sfgetfile(&where, "Select data file╔", NULL, 1, typelist, NULL, &reply);
- if (reply.good)
- {
- SetIText((Handle) cntl[4], reply.fName);
- temp_vRefNum = reply.vRefNum;
- HiliteControl(cntl[1], 0);
- }
- break;
- case 10: case 12: case 14:
- case 18: case 19: case 20: case 21:
- SetCtlValue(cntl[itemHit], !GetCtlValue(cntl[itemHit]));
- break;
- case 15: case 16: case 17:
- for (i = 15; i <= 17; i++)
- SetCtlValue(cntl[i], itemHit == i);
- break;
- }
- }
- while (itemHit != 1 && itemHit != 2);
-
- if (itemHit == 1)
- {
- getitext((Handle) cntl[4], settings->filename);
- settings->vRefNum = temp_vRefNum;
- getitext((Handle) cntl[5], s1); sscanf(s1, "%hd", &settings->width);
- PinValue(&settings->width, 0, 4095);
- getitext((Handle) cntl[6], s1); sscanf(s1, "%hd", &settings->height);
- PinValue(&settings->height, 0, 4095);
- getitext((Handle) cntl[7], s1); sscanf(s1, "%hd", &settings->quality);
- getitext((Handle) cntl[8], s1); sscanf(s1, "%hd", &settings->from);
- PinValue(&settings->from, 0, settings->height);
- getitext((Handle) cntl[9], s1); sscanf(s1, "%hd", &settings->to);
- PinValue(&settings->to, settings->from, settings->height);
- settings->antialias = GetCtlValue(cntl[10]);
- getitext((Handle) cntl[11], s1); sscanf(s1, "%f", &settings->threshold);
- settings->use_buf = GetCtlValue(cntl[12]);
- getitext((Handle) cntl[13], s1); sscanf(s1, "%hd", &settings->bufsize);
- settings->cr_file = GetCtlValue(cntl[14]);
- settings->dump = GetCtlValue(cntl[15]);
- settings->raw = GetCtlValue(cntl[16]);
- settings->targa = GetCtlValue(cntl[17]);
- settings->resume = GetCtlValue(cntl[18]);
- settings->pause = GetCtlValue(cntl[19]);
- settings->verbose = GetCtlValue(cntl[20]);
- settings->debug = GetCtlValue(cntl[21]);
- getitext((Handle) cntl[22], settings->paths);
-
- if (*settings->filename)
- {
- ARGC = 0;
- argptr = argstr;
- AddArg("DKBTrace");
- AddArg("+d0");
- AddArg("-x");
- sprintf(s1, "-w%d", settings->width); AddArg(s1);
- sprintf(s1, "-h%d", settings->height); AddArg(s1);
- sprintf(s1, "-s%d", settings->from); AddArg(s1);
- sprintf(s1, "-e%d", settings->to); AddArg(s1);
- if (settings->antialias)
- {
- sprintf(s1, "+a%.2f", settings->threshold);
- AddArg(s1);
- }
- else
- AddArg("-a");
- if (settings->use_buf)
- {
- sprintf(s1, "-b%d", settings->bufsize);
- AddArg(s1);
- }
- sprintf(s1, "-q%d", settings->quality); AddArg(s1);
- AddArg(settings->cr_file ? settings->dump ? "+fd" : settings->raw ?
- "+fr" : "+ft" : "-f");
- AddArg(settings->resume ? "+c" : "-c");
- AddArg(settings->pause ? "+p" : "-p");
- AddArg(settings->verbose ? "+v" : "-v");
- AddArg(settings->debug ? "+z" : "-z");
- sprintf(s1, "-i%s", settings->filename); AddArg(s1);
-
- /* Strip .dat or .data off end of inputfilename. */
- strcpy(s2, settings->filename);
- if ((i = strlen(s2)) > 4)
- {
- s2_p = s2 + i - 4;
- if (equalstring(s2_p, ".dat", false, true)
- || i > 5 && equalstring(--s2_p, ".data", false, true))
- *s2_p = 0;
- }
- /* Append appropriate extension. For Raw files, DKB takes care of this. */
- if (settings->dump)
- strcat(s2, ".dis");
- else
- if (settings->targa)
- strcat(s2, ".tga");
- sprintf(s1, "-o%s", s2); AddArg(s1);
-
- /* Add -l options for library paths. */
- strcpy(s2, settings->paths);
- c = *s2;
- s3_p = s2_p = s2;
- while (c)
- {
- while (*s3_p && *s3_p != 13)
- s3_p++;
- c = *s3_p;
- *s3_p = 0;
- /* Remove trailing ':'; DKB takes care of appending that. */
- if (*(s3_p - 1) == ':')
- *(s3_p - 1) = 0;
- if (*s2_p)
- {
- sprintf(s1, "-l%s", s2_p);
- AddArg(s1);
- }
- s2_p = ++s3_p;
- }
-
- Stop_Flag = 0;
- run_flag = 1;
- SetVol(NULL, settings->vRefNum);
- }
- }
- DisposDialog(myDialog);
- }
-
- void UpdateMenus(void)
- {
- if (dkb_runs)
- {
- DisableItem(myMenus[1], 1);
- DisableItem(myMenus[2], 1);
- EnableItem(myMenus[2], 2);
- }
- else
- {
- EnableItem(myMenus[1], 1);
- EnableItem(myMenus[2], 1);
- DisableItem(myMenus[2], 2);
- }
- CheckItem(myMenus[4], 1, settings->dither);
- }
-
- void DoCommand(long m)
- {
- short theMenu, theItem;
- Str255 name;
-
- theMenu = m >> 16;
- theItem = m;
- switch (theMenu)
- {
- case 1:
- if (theItem == 1)
- AboutDKB();
- else
- {
- GetItem(myMenus[1], theItem, name);
- OpenDeskAcc(name);
- }
- break;
-
- case 2:
- switch (theItem)
- {
- case 1: if (!run_flag) StartDKB(); break;
- case 2: Stop_Flag = 1; break;
- case 4: Stop_Flag = quit_flag = 1;
- }
- break;
-
- case 3:
- SystemEdit(theItem - 1);
- break;
-
- case 4:
- settings->dither = !settings->dither;
- if (plot_window)
- {
- SetPort(plot_window);
- InvalRect(&plot_window->portRect);
- }
- }
- HiliteMenu(0);
- }
-
- void DoMouseDown(void)
- {
- short code, part;
- WindowPtr whichWindow;
- ControlHandle whichControl;
-
- code = FindWindow(myEvent.where, &whichWindow);
- switch (code)
- {
- case inMenuBar:
- UpdateMenus();
- DoCommand(MenuSelect(myEvent.where));
- break;
- case inSysWindow:
- SystemClick(&myEvent, whichWindow);
- break;
- case inDrag:
- DragWindow(whichWindow, myEvent.where, &qd.screenBits.bounds);
- break;
- case inContent:
- if (whichWindow != FrontWindow())
- SelectWindow(whichWindow);
- else
- {
- SetPort(whichWindow);
- GlobalToLocal(&myEvent.where);
- part = FindControl(myEvent.where, whichWindow, &whichControl);
- if (whichControl == NULL) break;
- cur_wnd = whichControl != myScroll[0];
- switch (part)
- {
- case inUpButton:
- TrackControl(whichControl, myEvent.where, (ProcPtr) ScrollUp);
- break;
- case inDownButton:
- TrackControl(whichControl, myEvent.where, (ProcPtr) ScrollDown);
- break;
- case inPageUp:
- PageScroll(part, -wheight + 1);
- break;
- case inPageDown:
- PageScroll(part, wheight - 1);
- break;
- case inThumb:
- {
- TrackControl(whichControl, myEvent.where, NULL);
- ScrollBits();
- }
- }
- }
- }
- }
-
- void DoKeyDown(void)
- {
- char theChar;
-
- theChar = myEvent.message & charCodeMask;
- if (theChar == 27)
- waiting_for_esc = 0;
- else if (theChar == 5 && !dkb_runs)
- {
- HiliteMenu(1);
- AboutDKB();
- HiliteMenu(0);
- }
- else if (myEvent.modifiers & cmdKey)
- {
- UpdateMenus();
- DoCommand(MenuKey(theChar));
- }
- }
-
- void DoUpdateEvt(void)
- {
- WindowPtr wnd;
- BitMap bmap;
-
- wnd = (WindowPtr) myEvent.message;
- BeginUpdate(wnd);
- SetPort(wnd);
- if (wnd == plot_window)
- {
- if (plot_pixmap)
- {
- bmap.baseAddr = (Ptr) pm;
- bmap.rowBytes = 0xC000;
- CopyBits(&bmap, &wnd->portBits, &plot_bounds, &plot_bounds,
- settings->dither ? ditherCopy : srcCopy, NULL);
- }
- }
- else
- {
- cur_wnd = wnd != myWindow[0];
- TextFont(4);
- TextSize(9);
- UpdateText();
- if (active[cur_wnd])
- DrawControls(myWindow[cur_wnd]);
- else
- FrameRect(&(*myScroll[cur_wnd])->contrlRect);
- }
- EndUpdate(wnd);
- }
-
- void Activate(WindowPtr theWindow)
- {
- if ((cur_wnd = (theWindow == myWindow[1])) || theWindow == myWindow[0])
- {
- SetPort(myWindow[cur_wnd]);
- ShowControl(myScroll[cur_wnd]);
- active[cur_wnd] = 1;
- }
- }
-
- void Deactivate(WindowPtr theWindow)
- {
- if ((cur_wnd = (theWindow == myWindow[1])) || theWindow == myWindow[0])
- {
- SetPort(myWindow[cur_wnd]);
- HideControl(myScroll[cur_wnd]);
- FrameRect(&(*myScroll[cur_wnd])->contrlRect);
- active[cur_wnd] = 0;
- }
- }
-
- void DoActivateEvt(void)
- {
- if (myEvent.modifiers & 1)
- Activate((WindowPtr) myEvent.message);
- else
- Deactivate((WindowPtr) myEvent.message);
- }
-
- void DoApp4Evt(void)
- {
- if (myEvent.message >> 24 == 1)
- {
- if (myEvent.message & 1)
- Activate(FrontWindow());
- else
- Deactivate(FrontWindow());
- SetCursor(&qd.arrow);
- }
- }
-
- void DoNullEvt(void)
- {
- char s[256];
- long pos;
-
- if (myEvent.when - prev_upd_cons > 60)
- {
- cur_wnd = 0;
- for (;;)
- {
- pos = ftell(my_out);
- fseek(my_out, pos, SEEK_SET);
- if (fgets(s, 256, my_out) == NULL) break;
- PrintLine(s);
- }
- cur_wnd = 1;
- for (;;)
- {
- pos = ftell(my_err);
- fseek(my_err, pos, SEEK_SET);
- if (fgets(s, 256, my_err) == NULL) break;
- PrintLine(s);
- }
- prev_upd_cons = myEvent.when;
- }
- if (plot_window && plot_pixmap && settings->dither
- && myEvent.when - prev_upd_plot > 3600)
- {
- SetPort(plot_window);
- InvalRect(&plot_window->portRect);
- prev_upd_plot = myEvent.when;
- }
- }
-
- void MacDawdle(void)
- {
- WaitNextEvent(everyEvent, &myEvent, 0, NULL);
- switch (myEvent.what)
- {
- case mouseDown: DoMouseDown(); break;
- case keyDown: DoKeyDown(); break;
- case updateEvt: DoUpdateEvt(); break;
- case activateEvt: DoActivateEvt(); break;
- case app4Evt: DoApp4Evt(); break;
- case nullEvent: DoNullEvt();
- }
- }
-
- void MacBrag(void)
- {
- printf(" Ported to MPW, and Mac front-end added, by Thomas Okken.\n\n");
- }
-
- main()
- {
- long stk_size;
- int i;
- Rect r;
- Handle h;
- CTabHandle ctH;
- SysEnvRec theWorld;
-
- /* Allocate more memory for stack. */
- h = Get1Resource('CNFG', 128);
- stk_size = ** ((long **) h);
- ReleaseResource(h);
- SetApplLimit(GetApplLimit() - stk_size);
- MaxApplZone();
-
- /* Initialize toolbox managers. */
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(NULL);
- InitCursor();
- SetCursor(&qd.arrow);
- FlushEvents(everyEvent, 0);
- for (i = 1; i <= 3; i++)
- GetNextEvent(everyEvent, &myEvent);
- prev_upd_cons = prev_upd_plot = myEvent.when;
-
- /* Check if the necessary hard- & software is present. */
- if (SysEnvirons(1, &theWorld) != noErr || theWorld.processor < env68020
- || !theWorld.hasFPU || theWorld.systemVersion < 0x0605 || !theWorld.hasColorQD
- || NGetTrapAddress(0xAB03, ToolTrap) == NGetTrapAddress(0xA89F, ToolTrap))
- {
- StopAlert(129, NULL);
- ExitToShell();
- }
-
- /* Set up menus. */
- for (i = 1; i <= 4; i++)
- myMenus[i] = GetMenu(i + 127);
- AddResMenu(myMenus[1], 'DRVR');
- for (i = 1; i <= 4; i++)
- InsertMenu(myMenus[i], 0);
- DrawMenuBar();
-
- /* Redirect stdout and stderr to files; open those for reading. */
- freopen("DKB.out", "w", stdout);
- freopen("DKB.err", "w", stderr);
- SetTypeAndCreator("DKB.out", 'TEXT', 'MPS ');
- SetTypeAndCreator("DKB.err", 'TEXT', 'MPS ');
- setvbuf(stdout, buf0, _IOLBF, MYBUFSIZE);
- setvbuf(stderr, buf1, _IOLBF, MYBUFSIZE);
- my_out = fopen("DKB.out", "r");
- my_err = fopen("DKB.err", "r");
-
- /* Initialize console windows. */
- myText = (TEXTPTR) NewPtr(2 * maxlines * (wwidth + 1));
- r = tRect;
- OffsetRect(&r, 3, 59);
- r.right += 16;
- myWindow[1] = NewWindow(NULL, &r, "\pError", true, noGrowDocProc, myWindow[0], false, 0);
- OffsetRect(&r, 6, -19);
- myWindow[0] = NewWindow(NULL, &r, "\pOutput", true, noGrowDocProc, (WindowPtr) -1, false, 0);
- r = tRect;
- InsetRect(&r, -1, -1);
- r.left = r.right;
- r.right += 16;
- myScroll[0] = NewControl(myWindow[0], &r, "", true, 0, 0, 0, scrollBarProc, 0);
- myScroll[1] = NewControl(myWindow[1], &r, "", true, 0, 0, 0, scrollBarProc, 0);
- InsetRect(&tRect, margin, margin);
-
- /* Get saved settings for Trace╔ dialog. */
- theUpdateRgn = NewRgn();
- settings_h = (set_rec **) GetResource('SETT', 128);
- MoveHHi((Handle) settings_h);
- HLock((Handle) settings_h);
- settings = *settings_h;
- *(settings->filename) = 0;
-
- /* Set up offscreen pixmap. */
- ctH = (CTabHandle) NewHandle(sizeof(ColorTable));
- (*ctH)->ctSeed = 24;
- (*ctH)->ctFlags = 0;
- (*ctH)->ctSize = 0;
- pm = (PixMapHandle) NewHandle(sizeof(PixMap));
- (*pm)->pmVersion = 0;
- (*pm)->packType = 0;
- (*pm)->packSize = 0;
- (*pm)->hRes = 0x480000;
- (*pm)->vRes = 0x480000;
- (*pm)->pixelType = RGBDirect;
- (*pm)->pixelSize = 32;
- (*pm)->cmpCount = 3;
- (*pm)->cmpSize = 8;
- (*pm)->planeBytes = 0;
- (*pm)->pmTable = ctH;
- (*pm)->pmReserved = 0;
-
- /* Main event loop, sort of. */
- while (!quit_flag)
- {
- MacDawdle();
- if (run_flag)
- {
- call_main(ARGC, ARGV);
- SysBeep(10);
- }
- else
- if (quit_flag) break;
- }
-
- /* Clean up & exit. */
- DisposeWindow(myWindow[0]);
- DisposeWindow(myWindow[1]);
- DisposPtr((Ptr) myText);
- fclose(my_out);
- fclose(my_err);
- HUnlock((Handle) settings_h);
- ChangedResource((Handle) settings_h);
- ExitToShell();
- }
-